<?php
//if($_SESSION['sid']=='')
   // {
    //    fs_showmsg('请登录后再发送!','?');
   // }
?>
<div style="height:550px;width: 100%" id="sidebar_left">
<div class="m_leftbar">
    <dl>
				<dt>
					<a  href="#">互动交流</a>
				</dt>
    </dl>
    <ul>
         <?php
        if($_SESSION['type']=='')
        {
            fs_showmsg('请先登录!','?');
        }
        else
        {
            if($_SESSION['type']=='3')
            { 
?>
         <li><a href="?do=message">发邮件</a></li>
        <li><a href="?do=inbox">已发邮件</a></li>
         <li><a href="?do=groupmail&c=already">班级邮件</a></li>
        <li><a href="?do=draft">草稿箱</a></li>
        <?php
            }
            elseif($_SESSION['type']=='2')
            {?>
        <li><a href="?do=message">发邮件</a></li>
        <li><a href="?do=groupmail">已发邮件</a></li>
        <li><a href="?do=message&c=already">收件箱</a></li>
        <li><a href="?do=inbox&c=already">已回复信息</a></li>
        <?php
            }
            else{
                fs_showmsg('您既不是学生也不是老师,不能使用该功能!','?');
            }
        }
        ?>
    </ul>
</div>

<div class="m_rightbar">
   <div class="m_title"> <?php if($_GET['c']!='already'){?>已发邮件<?php }else{ ?>班级邮件<?php }?></div>
            <div class="m_sendbox">
                <form action="" method="post" name="form1" >
                <table cellspacing="0" cellpadding="0" id="messagelist">
                    <?php
                    if($_GET['c']!='already')
                    {//老师?>
                    <tr class="td_head">
                        <td style="width: 5%">选中</td>
                        <td>收件班级</td>
                        <td>主题</td>
                        <td>发送时间</td>
                        <td>操作</td>
                    </tr>
                    
                        <?php
                            $sql ="select * from nettteach_message  where m_from=".$_SESSION['sid']." order by sendtime desc";
                            $query  =$db->query($sql);
                            while($row = $db->fetch_array($query))
                            {?>
                        <tr class="list_list" >
                            <td><input name='id' type="checkbox" value=<?php echo($row['m_id']);?>></td>
                            <td><?php echo fs_get_objinfo("nettteach_class", "id", $row['to_classid'], "name")?></td>
                            <td><?php echo $row['object']?></td>
                            <td><?php echo date('Y-m-d H:i:s',$row['sendtime'])?></td>
                            <td><a href="?do=viewmessage&c=already&id=<?php echo $row['m_id']?>">查看</a></td>
                             </tr>
                                <?php
                            }
                        ?>
                  <?php
                    }
                    else{
                        ?>
                              <tr class="td_head" >
                                <td>发件人</td>
                                <td>主题</td>
                                <td>发送时间</td>
                                <td>操作</td>
                            </tr>
                            <?php
                            //学生
                           
                            $sql =" select * from nettteach_message where to_classid =(select classid from nettteach_member where id = ".$_SESSION['sid'].") order by sendtime desc";
                            $query = $db->query($sql);
                            while($row = $db->fetch_array($query))
                            {
                            ?>
                            <tr class="list_list">
                                <td><?php echo fs_get_objinfo("nettteach_member", "id", $row['m_from'], "realname")?></td>
                                <td><?php echo $row['object']?></td>
                            <td><?php echo date('Y-m-d H:i:s',$row['sendtime'])?></td>
                            <td><a href="?do=viewmessage&c=already&id=<?php echo $row['m_id']?>">查看</a></td>
                            </tr>
                        <?php
                            }
                    }
?>
                             
                   
                </table>
            </form>
                <?php  if($_SESSION['type']=='2'){?>
                <div style="padding-left: 10px;line-height: 27px;">
                    <INPUT onclick=CheckAll('selectAll',this) type=checkbox value=on name=chkall>全选
                    <input type="checkbox" name="invest" value="checkbox" onClick="CheckAll()">反选
                    <input type="checkbox" name="invest" value="checkbox" onClick="CheckAll('deleteAll',0)">全不选&nbsp;&nbsp;&nbsp;&nbsp;
                    <?php if($_GET['c']!='already'){?>
                    <input type=submit name="deletestudent" id="delete" style="font-size:9pt;width:50px;" value="删除" onclick="getCheckStu()" >
                    <?php }?>
                </div>
                <?php }?>
            </div>
</div>
</div>
<script type="text/javascript">
//    CKEDITOR.replace( 'm_content',{ height : '100px', width:'600px',toolbar:'MyToolbar',fontSize_sizes:'16/16px' } );
function getCheckStu(){
     var result=new Array();
     if(!document.form1.id.length){ 
        if(document.form1.id.checked){
             result.push(document.form1.id.value)
             }
    } 
    else{ 
         for(i=0;i<document.form1.id.length;i++){
             if(document.form1.id[i].checked){
             result.push(document.form1.id[i].value)
             }
         }
    }
//     alert(result);
if(confirm("是否删除")){
     if(result ==''){
         alert("请选择要删除的邮件");
         return false;
     }else{
            window.location.href="?do=groupmail&studeid="+result;
     }
}
}
</script>
<?php
if($_SESSION['sid']!='' && $_GET['studeid']!='')
{
    $userid = $_SESSION['sid'];
    $deleteid = $_GET['studeid'];
    $deid=explode(",", $deleteid);
    if($deid!='')
    {
        foreach ($deid as $deid){
                    $update_sql  = "delete from  nettteach_message  where m_from=".$userid." and m_id=".$deid;
                    $db->query($update_sql);
        
        }
                fs_showmsg('删除成功');
    }
    else
    {
        fs_showmsg('请选择要删除的邮件!');
    }
}
?>
